﻿using SqlSugar;
using System;

namespace Zhao.Repository.UnitOfWork
{
    public class UnitOfWork : IUnitOfWork
    {
        private readonly ISqlSugarClient _sqlSugarClient;

        public UnitOfWork(ISqlSugarClient sqlSugarClient)
        {
            _sqlSugarClient = sqlSugarClient;
        }


        public SqlSugarClient GetDbClient()
        {
            return _sqlSugarClient as SqlSugarClient;
        }

        public void BeginTran()
        {
            GetDbClient().BeginTran();
        }

        public void CommitTran()
        {
            try
            {
                GetDbClient().CommitTran();
            }
            catch //(Exception ex)
            {
                GetDbClient().RollbackTran();
                //写日志
            }
        }

        public void RollbackTran()
        {
            GetDbClient().RollbackTran();
        }

    }

}
